package com.css.bjdt_core.validation;

import java.util.ArrayList;
import java.util.List;

import com.css.bjdt_core.cell.entity.Cell;
import com.css.bjdt_core.executive.entity.Exp;
import com.css.bjdt_core.executive.util.ExpParser;
import com.css.bjdt_core.util.ReportConstant;

public class ValidationExpParser extends ExpParser {

	//private static ValidationExpParser instance;

	public ValidationExpParser() {
	}

	/*public static ValidationExpParser getInstance() {
		if (instance == null) {
			instance = new ValidationExpParser();
		}
		return instance;
	}*/

	@Override
	public void parseExp(Cell cell) {
		handleRowExpValidation(cell);
		handleColExpValidation(cell);
	}

	@Override
	protected void handleResult(Cell cell) {
		if (cell.getCalcExp().getCellExp() != null) {
			List<Exp> list = cell.getValidationExps();
			if (list == null) {
				list = new ArrayList<Exp>();
				cell.setValidationExps(list);
			}
			String oldExp = cell.getOldExp();
			String[] array = oldExp.split(ReportConstant.OPERATOR_RELA);
			String validationExp = oldExp.replaceFirst(array[0], cell.getKey()).replace(array[1],
					cell.getCalcExp().getCellExp());
			Exp e = new Exp();
			e.setFormulaType(cell.getCalcExp().getFormulaType());
			e.setCellExp(validationExp);
			e.setFormula(oldExp);
			e.setFormulaShow(cell.getCalcExp().getFormulaShow());
			list.add(e);
		}
	}

}
